package com.mallcai.bigdata.ladon.service.peekdata.sql;

import com.google.common.base.Preconditions;
import com.mallcai.bigdata.ladon.dpl.vo.AggFunction;

/**
 * @author feixy
 * @version 1.0
 * @date 2019-07-03 14:18
 */
public class MeasureField implements SqlField {

    private String name;

    private AggFunction aggFunction;

    public MeasureField(String name, String aggExpression) {
        this.name =  Preconditions.checkNotNull(name, "字段名不能为空");
        this.aggFunction = Preconditions.checkNotNull(AggFunction.getByCode(aggExpression),"非法的聚合函数");
    }

    @Override
    public String toSql() {
        return this.aggFunction.toSql(this.name);
    }
}
